<template>
  <div class='role-management-container treatment_div1 display header'>
    <el-card class="box-card">
      <template #header>
        <div class="customerTitle1">
          <div>
            <span><span class="leve_title" >{{customerListInFo && customerListInFo.buyer_customer_name+'-'}}{{title(groupList?.type)}}</span>
             <div class="add_order_font1"  v-if="route.query.path ==1 || route.query.path ==2">
           <span>
             <span>
               需求编码：
             </span>
             <span>
               {{customerListInFo && customerListInFo.order_no}}
             </span>
           </span>
            <span>
             <span class="add_order_font2">
               订单状态：
             </span>
             <span >
               {{customerListInFo && customerListInFo.status_str}}
             </span>
           </span>
              <span class="add_order_font2">销售员：{{customerListInFo && customerListInFo.sales_dept_name }}部门-{{customerListInFo && customerListInFo.undertaker_name}} </span>
           </div>
               <div class="add_order_font1"  v-if="route.query.path !=1 && route.query.path !=2">
           <span>
             <span>
               总单号：
             </span>
             <span>
               {{groupList && groupList.uid}}
             </span>
           </span>
            <span>
             <span class="add_order_font2">
               订单状态：
             </span>
             <span >
              {{groupList && groupList.status_str }}
             </span>
           </span>
              <span class="add_order_font2">销售员：{{groupList && groupList.sales_dept_name || ''}}部门- {{ groupList && groupList.update_user_name || ''}} </span>
           </div>
            </span>

          </div>
          <div v-if="route.query.path ==2">
            <el-button
              @click="back"
            >
              <!--              {{route.query.path != 5? route.query.path == 1 ? '取消承接' :'取消':'返回'}}-->
              {{'返回'}}
            </el-button>
          </div>
          <div v-if="route.query.path !=2">
            <el-button
              :class="route.query.path == 1 ?'customerButton2':''"
              @click="back"
            >
<!--              {{route.query.path != 5? route.query.path == 1 ? '取消承接' :'取消':'返回'}}-->
              {{route.query.path == 1 ? '取消承接' :'返回'}}
            </el-button>
            <el-button
              class="customerButton1"
              v-if="groupList && groupList.status != '1' && route.query.path != 5 || customerListInFo && customerListInFo.status_str !== '已保存'  && route.query.path != 5"
              plain
              type="primary"
              @click="submit(form_date,0)"
            >
              暂存
            </el-button>
            <el-button
              v-if="route.query.path != 5"
              class="customerButton1"
              plain
              type="primary"
              @click="submit(form_date,1)"
            >
              保存
            </el-button>
            <el-button v-if="route.query.path != 5"  type="primary" @click="submit(form_date,2)">
              提交
            </el-button>
          </div>
        </div>
      </template>
      <div>
        <VabStep :active="active" :steps="route.query.path == 1 || route.query.path == 2 ? arr_approve:arr_approve1"/>
      </div>
    </el-card>
    <el-card class="box-card">
      <template #header>
        <div class="customerTitle1">
          <span class="leve2_title leave3Title titleHead1">订单信息</span>
          <div v-if="route.query.path !=2">
            <el-button
              class="customerButton1"
              v-if="route.query.path != 5 && route.query.path != 1"
              plain
              type="primary"
              @click="create_list"
            >
              新建订单
            </el-button>
<!--            <el-button
              v-if="route.query.path != 5 && route.query.path != 1"
              class="customerButton1"
              plain
              size="small"
              type="primary"
              @click="copy"
            >
              复制
            </el-button>-->
            <el-button   class="customerButton2" v-if="route.query.path != 5" @click="cancellation">删除</el-button>
          </div>
        </div>
      </template>
      <div>
        <el-table
          ref="singleTableRef"
          highlight-current-row
          :load="loading"
          border
          :data="customer_order_list"
          max-height="300px"
          style="width: 100%"
          class="table_style1"
          @current-change="handleCurrentChange"
        >
          <el-table-column label="序号" align="center" width="80" fixed="left">
            <template #default="scope">
            <div class="table_style">
              <label class="el-checkbox"
                     :class="{ 'is-checked': radioIndex && radioIndex.id === scope.row.id }"
                     @click="handleRadio(scope.row)"
                     v-if="route.query.path != 5 && route.query.path != 2"
              >
                <span class="el-checkbox__input" :class="{ 'is-checked': radioIndex && radioIndex.id == scope.row.id }"><span class="el-checkbox__inner"></span></span>
              </label>
              <span style="margin-left: 5px"
                    v-text="(scope.$index + 1)"
              ></span>
            </div>
            </template>
          </el-table-column>
          <el-table-column label="订单编号" align="center" width="150" fixed="left">
            <template #default="scope">
               <span
                 v-if="route.query.path != 5 && route.query.path !=2"
                 class="ellipsis textFont"
                 @click="upData(scope.row)"
               >
              {{ _FieldFormat(scope.row.uid,  '')}}
             </span>
              <span
                v-if="route.query.path == 5 || route.query.path ==2"
                class="ellipsis"
              >
              {{ _FieldFormat(scope.row.uid,  '')}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="客户" align="center" width="170">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.customer_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="销售组织" align="center" width="150">
            <template #default="scope">
              <span
                class="ellipsis"
              >
               {{scope.row.sales_org_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="价目表" align="center" width="130">
            <template #default="scope">
              <span
                class="ellipsis"
              >
             {{scope.row.price_list_name || '--'}}
             </span>
            </template>
          </el-table-column>
<!--          <el-table-column label="折扣赠品策略" align="center" width="130">
            <template #default="scope">
              <span
                class="ellipsis"
              >
             {{scope.row.discount_name || '&#45;&#45;'}}
             </span>
            </template>
          </el-table-column>-->
          <el-table-column label="结算币别" align="center" width="130">
            <template #default="scope">
              <span
                class="ellipsis"
              >
             {{scope.row.trading_curr_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="开票类型" align="center" width="130">
            <template #default="scope">
              <span
                class="ellipsis"
              >
             {{scope.row.invoice_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="销售数量" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              {{scope.row.sales_num||'--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="计价数量" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              {{scope.row.pricing_num||'0'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="不含税金额" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              ￥
              {{scope.row.amount || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="税额" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.tax || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="价税合计" align="center" width="130">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              ￥
              {{scope.row.total_amount || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="期望运输方式" align="center" width="110">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.transport_type_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="运费付款方式" align="center" width="130">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.payment_type == '1'?'运费到付':'运费预付'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="收货地址" align="center" width="150">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.shipping_address}}
              {{scope.row.address}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="收货联系人" align="center" width="110">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.contact_user || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="联系电话" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.contact_tel || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center" width="150">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.remark || '--'}}
             </span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <el-card class="box-card" v-if="route.query.path != 1 && route.query.path != 2">
      <template #header>
        <div class="customerTitle1">
          <span class="leve2_title leave3Title titleHead1">产品信息<span class="title1">{{detailList && "订单编号" +detailList.uid}}</span></span>
        </div>
      </template>
      <div>
        <el-table
          :load="detailLoading"
          border
          :data="detailList && detailList.detail"
          max-height="200px"
          style="width: 100%"
          class="table_style1"
        >
          <el-table-column label="序号" align="center" width="80" fixed="left">
            <template #default="scope">
              <div class="table_style">
                <span style="margin-left: 5px"
                      v-text="(scope.$index + 1)"
                ></span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="产品类型" align="center" width="100" fixed="left">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.goods_type || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="产品编码" align="center" fixed="left" width="120">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.goods_no || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="产品名称" align="center" fixed="left" width="170">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.goods_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="条码" align="center" width="150">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.barcode || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="规格型号" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.spec_name.trim() || '--'}}
             </span>
            </template>
          </el-table-column>

          <el-table-column label="销售数量" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              {{scope.row.sales_num || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="仓库" align="center" width="120"  v-if="groupList && groupList.type !== 2">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.warehouse_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="调出仓库" align="center" width="120" v-if="groupList && groupList.type == 2">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.warehouse_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="调入仓库" align="center" width="120"  v-if="groupList && groupList.type == 2">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.consignment_warehouse_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="效期备注" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.expire_date_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="批次号备注" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.batch_no || '--'}}
             </span>
            </template>
          </el-table-column>

          <el-table-column prop="batch_usable_num" label="价目表价格" align="center" width="150">
            <template #default="props">
                 <span class="ellipsis numberMoney">
                    ￥{{Number(props.row.price).toFixed(2) || 0.00 }}
               </span>
            </template>
          </el-table-column>
          <el-table-column label="含税单价" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.including_tax_price || '--'}}
             </span>
            </template>
          </el-table-column>
                    <el-table-column label="改价原因" align="center" width="200">
                      <template #default="scope">
                        <span
                          class="ellipsis"
                        >
                        {{scope.row.price_remark || '--'}}
                       </span>
                      </template>
                    </el-table-column>
          <el-table-column label="税率" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              {{scope.row.tax_rate_name || '--'}}
             </span>
            </template>
          </el-table-column>

          <el-table-column label="预计可发量" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              {{scope.row.batch_usable_num || '0'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="价税合计" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.total_amount || '--'}}
             </span>
            </template>
          </el-table-column>
<!--          <el-table-column label="库存组织" align="center" width="200">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.stock_org_name || '&#45;&#45;'}}
             </span>
            </template>
          </el-table-column>-->
          <el-table-column label="销售单位" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.sales_unit || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="品牌" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.brand_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="不含税单价" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.order_price || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="税额" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.tax || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="不含税金额" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.amount || '--'}}
             </span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <el-card class="box-card" v-if="route.query.path == 1 || route.query.path == 2">
      <template #header>
        <div class="customerTitle1">
          <span class="titleHead1">产品信息<span class="title1">{{detailList && "订单编号" +detailList.uid}}</span></span>
        </div>
      </template>
      <div>
        <el-table
          :load="detailLoading"
          border
          :data="detailList && detailList.detail"
          max-height="200px"
          style="width: 100%"
          class="table_style1"
        >
          <el-table-column label="序号" align="center" width="80" fixed="left">
            <template #default="scope">
              <div class="table_style">
                <span style="margin-left: 5px"
                      v-text="(scope.$index + 1)"
                ></span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="产品类型" align="center" width="100" fixed="left">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.goods_type || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="产品编码" align="center" fixed="left" width="120">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.goods_no || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="产品名称" align="center" fixed="left" width="170">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.goods_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="条码" align="center" width="150">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.barcode || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="规格型号" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.spec_name.trim() || '--'}}
             </span>
            </template>
          </el-table-column>

          <el-table-column label="销售数量" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              {{scope.row.sales_num || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="仓库" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.warehouse_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="效期备注" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.expire_date_name || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="批次号备注" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.batch_no || '--'}}
             </span>
            </template>
          </el-table-column>

          <el-table-column prop="batch_usable_num" label="价目表价格" align="center" width="150">
            <template #default="props">
                 <span class="ellipsis numberMoney">
                    ￥{{Number(props.row.price).toFixed(2) || 0.00 }}
               </span>
            </template>
          </el-table-column>
          <el-table-column label="含税单价" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.including_tax_price || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="改价原因" align="center" width="200">
            <template #default="scope">
                        <span
                          class="ellipsis"
                        >
                        {{scope.row.price_remark || '--'}}
                       </span>
            </template>
          </el-table-column>
          <el-table-column label="税率" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              {{scope.row.tax_rate_name || '--'}}
             </span>
            </template>
          </el-table-column>

          <el-table-column label="预计可发量" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
              {{scope.row.batch_usable_num || '0'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="价税合计" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.total_amount || '--'}}
             </span>
            </template>
          </el-table-column>
<!--          <el-table-column label="库存组织" align="center" width="200">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.stock_org_name || '&#45;&#45;'}}
             </span>
            </template>
          </el-table-column>-->
          <el-table-column label="销售单位" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.sales_unit || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="品牌" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis"
              >
              {{scope.row.brand_name || '--'}}
             </span>
            </template>
          </el-table-column>

          <el-table-column label="不含税单价" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.order_price || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="税额" align="center" width="100">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.tax || '--'}}
             </span>
            </template>
          </el-table-column>
          <el-table-column label="不含税金额" align="center" width="120">
            <template #default="scope">
              <span
                class="ellipsis numberMoney"
              >
                ￥
              {{scope.row.amount || '--'}}
             </span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <el-dialog v-model="productQuantityOpen" width="60%" center>
      <template #header>
      <span>
        <el-icon style="font-size: 66px;color: #f7ae57"><WarningFilled /></el-icon>
        <div class="titleProduct">
          产品库存不足
        </div>
      </span>
      </template>
    <span>
    <div v-for="(item, index) in productQuantityList" :key="index">
      <p>
        {{item.goods_name}}产品销售数量{{Number(item.sales_num).toFixed(0)}},当前库存
      <span style="color: #f59a23">
        {{Number(item.quantity).toFixed(0)}}
      </span>
      ,库存不足,
      </p>
    </div>
      <div>
        请更新销售数量或者调拨后在进行订单提交
      </div>
    </span>
      <template #footer>
      <span class="dialog-footer">
          <el-button type="primary" @click="productQuantityOpen = false">
          知道了
        </el-button>
      </span>
      </template>
    </el-dialog>
   <AuditInformation  v-if="route.query.path == 2 || route.query.path == 5"/>
    <OrderLog ref="orderLog" />
    <CustomerNewOrder  v-if="route.query.path == 1" ref="pop_up" />
    <ConsignNewOrder v-else-if="route.query.path == 4" ref="pop_up" />
    <NewOrder  v-else ref="pop_up" />
  </div>
</template>

<script setup lang="ts">
import router from "/@/router";
import lodash from 'lodash';
import {ref} from "vue";
import {FieldFormat} from "/@/utils/utils";
import {ElMessage, ElMessageBox, FormRules} from "element-plus";
import {options_list} from "/@/api/dms/options";
import AuditInformation from './AuditInformation.vue'
import NewOrder from './NewOrder.vue'
import OrderLog from './OrderLog.vue'
import {
  orderGroupCancel,
  orderGroupCopy,
  orderGroupInfo,
  orderGroupInsert,
  orderGroupUpdate
} from "/@/api/dms/order/group";
import {orderCancel, orderDelete, orderInfo, orderList} from "/@/api/dms/order";
import CustomerNewOrder from '../customer_order/component/CustomerNewOrder.vue'
import ConsignNewOrder from '../consignOrder/component/ConsignNewOrder.vue'
import {customerOrderInfo, customerUndertake} from "/@/api/dms/customerOrder";
defineOptions({
    name: 'AddOrder',
  })
// 产品不足的弹窗
const productQuantityOpen = ref(false)
const productQuantityList = ref<any>([])
const route:any = useRoute()
const form_date = ref(null)
const loading = ref(false)
const orderPath:any = ref(localStorage.getItem('orderPath'))
const orderPath2:any = ref(localStorage.getItem('orderPath2'))
// 订单日志   changeLogRef.value._getCustomerPriceLog(id)
const  orderLog = ref<any>(null)
// 获取组
const groupList = ref<any>(undefined)
//route.query.path   1：客户创建订单  2：客户订单详情  3 ：员工创建订单 4：寄售订单  5 员工订单详情
const title=(va:any)=>{
  if(route.query.path == 4){
    return '寄售订单'
  }else if(route.query.path == 3){
    return '标准销售订单'
  }else if(route.query.path == 5){
    if(va == 2){
      return '寄售订单'
    }else{
      return '销售订单详情'
    }
  }else if(route.query.path == 2){
    return '销售订单详情'
  }else  if(route.query.path == 1){
    return '销售订单'
  }else {
    return '标准销售订单'
  }
}
const form_list = ref({
  trading_curr_id:'',
  base_curr_name:'人民币',
  exchange_rate_type:'',
  exchange_rate:'1.00000000',
  is_including_tax:1,
  extra_price_tax:1,
  invoice_type:''
})
const customer_order_list = ref([])

// *********** 工作流
const arr_approve = ref([
  { title: '客户需求', active: true, path:`/order/treatment?path=${route.query.path}&id=${route.query.order}`},
  { title: '销售订单', active: true, path:`/order/addOrder?path=${route.query.path}&id=${route.query.id || 0}&order=${route.query.order}` },
  { title: '销售出库单', active: false, path:`/order/retrieval?path=${route.query.path}&id=${route.query.id}&order=${route.query.order}` },
  { title: '快递运输', active: false },
  { title: '收货确认', active: false },
])
let arr_approve1 = ref<any>([
  { title: '销售订单', active: true,path:`/order/addOrder?path=${route.query.path}&id=${route.query.id}`},
  { title: '销售出库单', active: false,path:' ' },
  { title: '快递运输', active: false,path:' ' },
  { title: '收货确认', active: false,path:' ' },
])
const active = ref(1)
// ******************
const back = lodash.debounce(()=>{
  if(route.query.path == 1){
    ElMessageBox.confirm(
      `取消承接后，可由其他人员继续承接，您确认要取消吗？`,
      {
        confirmButtonText: '确定',
        cancelButtonText: '返回',
        type: 'warning',
      }
    )
      .then(() => {
        customerUndertake({order_no:route.query.order,type:2}).then((data:any)=>{
          if(data.code == 200){
            orderGroupCancel({uid:route.query.id,from:'undertakes'}).then((item:any)=>{
              if (item.code == 200){
                router.push('/order/customerOrder')
                ElMessage.success(`取消成功`)
              }
            })
          }
        })
      })
  }else if( route.query.path == 2) {
    if(orderPath2.value == 1){
      router.push('/order/customerOrder')
    }else {
      router.push('/order/orderQuery')
    }

  }if( route.query.path == 3) {
    if(orderPath.value == 1){
      router.push('/order/standardOrder')
    }else {
      router.push('/order/orderQuery')
    }
  }if( route.query.path == 4) {
    if(orderPath.value == 2){
      router.push('/order/consignOrder')
    }else {
      router.push('/order/orderQuery')
    }
  }if( route.query.path == 5) {
    if(orderPath.value == 1){
      router.push('/order/standardOrder')
    }else if(orderPath.value == 2){
      router.push('/order/consignOrder')
    }else {
      router.push('/order/orderQuery')
    }
  }if( route.query.path == 6) {
    router.push('/order/orderQuery')
  }
},500)
const _FieldFormat = (value: string, type = '') => {
  return FieldFormat(value, type)
}

//******表单验证*******
const rules = ref<FormRules<any>>({
  trading_curr_id: [{ required: true, message: '请选择结算币别', trigger: 'change' }],
  invoice_type: [{ required: true, message: '请选择开票类型', trigger: 'change' }],
})
// **************财务信息**************
let currency = ref([])
let exchange_rate_type_list = ref([{value:'1',label:'固定汇率'},{value:'2',label:'即期汇率'}])
let invoice_type_list = ref([])

const get_list=()=>{
  options_list({module:'currency'}).then((data:any)=>{
    // console.log(data,'币别')
    if(data.code == 200){
      currency.value = data.data?.map((i:any)=>{return {value:i.uid,label:i.name}}) || []
    }else {
      currency.value=[]
    }
  })
  options_list({module:'invoice_type'}).then((data:any)=>{
    // console.log(data,'币别')
    if(data.code == 200){
      invoice_type_list.value = data.data?.map((i:any)=>{return {value:i.uid,label:i.name}}) || []
    }else {
      invoice_type_list.value=[]
    }
  })
}
// ************* 新建 弹窗****************
const pop_up = ref<any>(null)
const create_list=()=>{
  pop_up.value.getGroupList = groupList.value
  pop_up.value.dialogVisibles = true
  pop_up.value.submit = false
  pop_up.value.copyList = null
  radioIndex.value = null
}
// 获取列表数据
const getOrderList =(id:any)=>{
  loading.value = true
  orderList({page:1,pagesize:2000,order_group_uid:id}).then((data:any)=>{
    if(data.code == 200){
      loading.value = false
      customer_order_list.value = data.data.list
      detailList.value = data.data.list[0]
      singleTableRef.value!.setCurrentRow(data.data.list[0])
    }
  })
}
// 结算币时间
const localCurrencyChange = ()=>{
  if(form_list.value.trading_curr_id != '' && form_list.value.exchange_rate_type !=''){
   const arr = [...groupList.value.rate_list ]
   const rate = arr.filter((item:any)=> item.f_cy_for_id == form_list.value.trading_curr_id && item.f_rate_type_id == form_list.value.exchange_rate_type  ) || undefined
    form_list.value.exchange_rate = rate[0]?.f_exchange_rate || '1.00000000'
  }
}
// 提交
const submit = lodash.debounce(async (value:any,status:number)=>{

  orderGroupUpdate({uid: groupList && groupList.value.uid,status:status}).then((data:any)=>{
    if(data.code == 200){
      if( !data.data.result && status != 0  ){
        productQuantityList.value = data.data.error_info || []
        productQuantityOpen.value = true
      }else {
        if(status == 0){
          ElMessage.success(`暂存成功`)
        }else if(status == 1){
          ElMessage.success(`保存成功`)
        }else if(status == 2){
          ElMessage.success(`提交成功`)
        }
        if(route.query.path == 1){
          router.push('/order/customerOrder')
         /* if(orderPath.value == 0){
            router.push('/order/orderQuery')
          }else {
            router.push('/order/customerOrder')
          }*/
        }else if( route.query.path == 2) {
          router.push('/order/customerOrder')
        }else if( route.query.path == 3) {
          router.push('/order/standardOrder')
         /* if(orderPath.value == 1){
            router.push('/order/standardOrder')
          }else {
            router.push('/order/orderQuery')
          }*/
        }else if( route.query.path == 4) {
          router.push('/order/consignOrder')
        /*  if(orderPath.value == 2){
            router.push('/order/consignOrder')
          }else{
            router.push('/order/orderQuery')
          }*/
        }

      }
    }
  }).catch((data:any)=>{
    if(data.data.code == 44202){
      // 采购订单没有标记的跳转
      router.push(`/order/treatment?path=${route.query.path}&id=${route.query.order}`)
    }
  })
  },500)


const radioIndex=ref<any>(undefined)
// 复制
const radioList=ref<any>(undefined)
const singleTableRef = ref<any>(undefined)

// 单选
const handleRadio = (row: any) => {
  radioIndex.value = row
  orderInfo({uid:row.uid}).then((data:any)=>{
    radioList.value = {...data.data,type:2}
  })

}
const copy = ()=>{
  if(radioList.value){
     pop_up.value.getGroupList = groupList.value
     pop_up.value.dialogVisibles = true
     pop_up.value.submit = false
     pop_up.value.copyList = radioList.value
    radioIndex.value = null
  }else {
    ElMessage.warning(`请先选择订单`)
  }
}
const upData = async (row:any)=>{
 await orderInfo({uid:row.uid}).then((data:any)=>{
   pop_up.value.copyList = {...data.data,type:1}
   pop_up.value.getGroupList = groupList.value
   pop_up.value.dialogVisibles = true
   pop_up.value.submit = false
   radioIndex.value = null
  })
}
// ********单选获取产品信息****************
const detailList = ref<any>(undefined)
const detailLoading = ref<any>(false)
const handleCurrentChange =(va:any)=>{
  detailList.value = va
}
const orderGroup = ()=>{
  if(route.query.id){
    orderGroupInfo({uid:route.query.id}).then((data:any)=>{
      if(data.code == 200){
        groupList.value = data.data
       /* if(data.data.payment.length == 0){
          form_list.value = {
            trading_curr_id:'',
            base_curr_name:'人民币',
            exchange_rate_type:'',
            exchange_rate:'1.00000000',
            is_including_tax:1,
            extra_price_tax:1,
            invoice_type:''
          }
        }else {
          form_list.value = {...data.data.payment,base_curr_name:data.data.payment.base_curr_name || '人民币',exchange_rate:data.data.payment.exchange_rate || '1.00000000'}
        }*/
        if(data.data.stock_out.length >0){
          if(data.data.is_express){
            arr_approve1.value = [
              { title: '销售订单', active: true,path:`/order/addOrder?path=${route.query.path}&id=${route.query.id}`},
              { title: '销售出库单', active: true,path:`/order/retrieval?path=${route.query.path}&id=${route.query.id}` },
              { title: '快递运输', active: true, path:`/order/expressCompany?path=${route.query.path}&id=${route.query.id}`},
              { title: '收货确认', active: true,path:`/order/receipt?path=${route.query.path}&id=${route.query.id}` },
            ]
          }else {
            arr_approve1.value = [
              { title: '销售订单', active: true,path:`/order/addOrder?path=${route.query.path}&id=${route.query.id}`},
              { title: '销售出库单', active: true,path:`/order/retrieval?path=${route.query.path}&id=${route.query.id}` },
              { title: '快递运输', active: false, path:`/order/expressCompany?path=${route.query.path}&id=${route.query.id}`},
              { title: '收货确认', active: false,path:`/order/receipt?path=${route.query.path}&id=${route.query.id}` },
            ]
          }

        }
        if( data.data.type == 2){
          arr_approve1.value[1].title='直接调拨单'
        }
      }
    })
    orderLog.value._getCustomerPriceLog(route.query.id)
  }else {
    //获取组id
    orderGroupInsert({type:route.query.path == 3?1:2}).then((data:any)=>{
      if(data.code == 200){
        groupList.value = data.data
        orderLog.value._getCustomerPriceLog(data.data.uid)
        if(route.query.path == 4){
          arr_approve1.value[1].title='直接调拨单'
        }
      }
    })
  }
}
// 订单删除
const cancellation = ()=>{
  if(radioIndex.value){
    ElMessageBox.confirm(
      `请确认是否取删除订单编号为：${radioIndex.value.uid}，销售组织为：${radioIndex.value.sales_org_name || ''}， 客户为：${radioIndex.value.customer_name || ''}的订单。`,
      {
        confirmButtonText: '确定',
        cancelButtonText: '返回',
        type: 'warning',
      }
    )
      .then(() => {
        orderDelete({uid:radioIndex.value.uid}).then((data:any)=>{
          if (data.code == 200){
            radioIndex.value = undefined
            ElMessage.success(`删除成功`)
            getOrderList(groupList.value.uid)
          }
        })
      })
  }else {
    ElMessage({
      message: '请先选择订单',
      type: 'warning',
    })
  }
}
// 客户端
const customerListInFo = ref<any>(undefined)
const getCustomerInfo = ()=>{
  if( route.query.order &&  route.query.path ==1 ||  route.query.path ==2){
    loading.value = true
    customerOrderInfo({order_no:route.query.order}).then((data:any)=>{
      if(data.code == 200){
        loading.value = false
        customerListInFo.value = data.data
      }
    })
  }
}
watch(groupList,()=>{
  if(groupList){
    getOrderList(groupList.value.uid)
  }
})
watchEffect(()=>{
  const {submit,copyList} = pop_up.value || {}
  if(submit){
    getOrderList(groupList.value.uid)
  }
  radioList.value = copyList
  //页签跳转
    if(customerListInFo.value && customerListInFo.value.stock_out.length >0){//销售出库
      if(customerListInFo.value.is_express){// 快递运输
        arr_approve.value =[
          { title: '客户需求', active: true, path:`/order/treatment?path=${route.query.path}&id=${route.query.order}`},
          { title: '销售订单', active: true, path:`/order/addOrder?path=${route.query.path}&id=${route.query.id || 0}&order=${route.query.order}` },
          { title: '销售出库单', active: true, path:`/order/retrieval?path=${route.query.path}&id=${route.query.id}&order=${route.query.order}` },
          { title: '快递运输', active: true, path:`/order/expressCompany?path=${route.query.path}&id=${route.query.id}&order=${route.query.order || 0}`},
          { title: '收货确认', active: true,path:`/order/receipt?path=${route.query.path}&id=${route.query.id}&order=${route.query.order || 0}` },
        ]
      }else {
        arr_approve.value =[
          { title: '客户需求', active: true, path:`/order/treatment?path=${route.query.path}&id=${route.query.order}`},
          { title: '销售订单', active: true, path:`/order/addOrder?path=${route.query.path}&id=${route.query.id || 0}&order=${route.query.order}` },
          { title: '销售出库单', active: true, path:`/order/retrieval?path=${route.query.path}&id=${route.query.id}&order=${route.query.order}` },
          { title: '快递运输', active: false, path:`/order/expressCompany?path=${route.query.path}&id=${route.query.id}&order=${route.query.order || 0}`},
          { title: '收货确认', active: false,path:`/order/receipt?path=${route.query.path}&id=${route.query.id}&order=${route.query.order || 0}` },
        ]
      }

    }
})
onMounted(()=>{
  // 客户
  getCustomerInfo()
  //获取结算币
  get_list()
//组id
  orderGroup()

})
</script>

<style lang="scss" scoped>
@import "../index";

.add_order_font1{
 margin-top: 12px;
  font-size: 12px;
  color: #9e9e9e;
}

.table_style1{
  padding:0px;
  :deep(){
    .el-table__expanded-cell{
      padding: 0px !important;
      border: 0px !important;
      padding-left: 46px !important;
      padding-right: 46px !important;
      background-color: #eee;
    }

  }
}
.bas{
  :deep(){
    .el-scrollbar{
      display: none;
    }
  }
}
.form_node{
  :deep(){
  .is-disabled{
      background-color: #fff;
    }
  }
}
.titleProduct{
  font-size: 20px;
  margin-top: 10px;
}
.titleProduct1{
  display: inline-block;width: 3px;height: 3px;background-color: #0a0a0a;margin-right: 10px;margin-bottom: 3px;border-radius: 50%
}
</style>

